import axios from 'axios'
import config from '@/config'

/**
 * 获取FunKey TasksNotify
 * @returns {AxiosPromise}
 */

export function getTasksNotify() {
  return axios({
    method: 'GET',
    url: config.serverURI + config.api.tasks_notification
  })
}

/**
 * 验证用户是否登录
 * @returns {AxiosPromise}
 */
export function auth() {
    return axios({
        method: 'get',
        url: config.serverURI + config.api.auth
    })
}

/**
 * 登录
 * @param username
 * @param password
 * @returns {AxiosPromise}
 */

export function login(username, password) {
    let data = 'username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password)
    return axios({
        method: 'post',
        url: config.serverURI + config.api.login,
        data
    })
}

/**
 * 注销
 * @returns {AxiosPromise}
 */

export function logout() {
    return axios({
        method: 'get',
        url: config.serverURI + config.api.logout
    })
}

export function generalSearch(query) {
    return axios({
        method: 'post',
        url: config.serverURI + config.api.general_search,
        data: {
            query
        }
    })
}

export function getAnnouncements() {
    return axios({
        method: 'get',
        url: config.serverURI + config.api.get_announcements,
    })
}

export function getIssues() {
    return axios({
        method: 'get',
        url: config.serverURI + config.api.get_issues_notification,
    })
}
